package net.miranti.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.VisualizationUtils;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.ImageLineChart;
import com.google.gwt.visualization.client.visualizations.ImageLineChart.Options;

public class Viz implements EntryPoint {

	public void onModuleLoad() {
		// Create a callback to be called when the visualization API has been loaded.
		Runnable onLoadCallback = new Runnable() {
			public void run() {
				Panel panel = RootPanel.get();

				ImageLineChart chart = new ImageLineChart(createTable(), createOptions());
				panel.add(chart);
			}
		};

		// Load the visualization api, passing the onLoadCallback to be called
		// when loading is done.
		VisualizationUtils.loadVisualizationApi(onLoadCallback, ImageLineChart.PACKAGE);
	}

	private Options createOptions() {
		Options options = Options.create();
		options.setWidth(1000);
		options.setHeight(240);
		options.setTitle("Month");
		return options;
	}

	private AbstractDataTable createTable() {
		DataTable data = DataTable.create();
		data.addColumn(ColumnType.STRING, "Month");
		data.addColumn(ColumnType.NUMBER, "AIRCRAFT");
		data.addRows(11);
		data.setValue(0, 0, "Jan-03");
		data.setValue(0, 1, 14);
		data.setValue(1, 0, "Fev-03");
		data.setValue(1, 1, 10);
		data.setValue(2, 0, "Mar-03");
		data.setValue(2, 1, 1);
		data.setValue(3, 0, "Abr-03");
		data.setValue(3, 1, 0);
		data.setValue(4, 0, "Jun-03");
		data.setValue(4, 1, 30);
		data.setValue(5, 0, "Jul-03");
		data.setValue(5, 1, 80);
		data.setValue(6, 0, "Ago-03");
		data.setValue(6, 1, 50);
		data.setValue(7, 0, "Set-03");
		data.setValue(7, 1, 30);
		data.setValue(8, 0, "Out-03");
		data.setValue(8, 1, 35);
		data.setValue(9, 0, "Nov-03");
		data.setValue(9, 1, 38);
		data.setValue(10, 0, "Dez-03");
		data.setValue(10, 1, 24);
		return data;
	}
}
